package org.example.ram;

import java.util.ArrayList;

public class Test {

    private byte[] bytes = new byte[1024*1024];

    public static void main(String[] args) {

        ArrayList<Test> objects = new ArrayList<>();
        int num = 0;
        try {
            while (true){
                    objects.add(new Test());
                    num++;
            }
        }catch (Throwable err){
            System.out.println("出现错误，共进行gc" + num + "次");
            err.printStackTrace();
        }

        System.out.println("total memory"+ Runtime.getRuntime().totalMemory()/1024/1024);
        System.out.println("free memory"+ Runtime.getRuntime().freeMemory()/1024/1024);
        System.out.println("max memory"+ Runtime.getRuntime().maxMemory()/1024/1024);
    }
}
